package com.motiom.gear.roomaction;

import android.arch.persistence.room.Room;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.support.v7.app.AppCompatActivity;

import com.motiom.gear.roomaction.dao.UserDao;
import com.motiom.gear.roomaction.db.UserDB;
import com.motiom.gear.roomaction.model.Address;
import com.motiom.gear.roomaction.model.User;

public class MainActivity extends AppCompatActivity {

    private HandlerThread workThread = new HandlerThread("work-thread");
    private Handler mWorkHandler = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        workThread.start();
        mWorkHandler = new Handler(workThread.getLooper());
        mWorkHandler.post(new Runnable() {
            @Override
            public void run() {
                UserDB db = Room.databaseBuilder(BaseApplication.getInstance(), UserDB.class, "user").build();
                UserDao dao = db.getUserDao();

                User user = new User();
                user.setName("wangxin");
                user.setGender("male");
                user.setAge(30);

                Address address = new Address();
                address.setCity("shanghai");
                address.setProvince("shanghai");
                address.setRoadName("chuang xin xi road");
                address.setBlock_num("Tang feng yuan");
                user.setAddress(address);

                dao.insertUser(user);

            }
        });

    }
}
